<template>
    <div class="integral_status">
        <x-header :left-options="{backText: ''}" >党员积分
          <a slot="right"  class="choose" @click="changChoose()"></a>
        </x-header>
        <div class="integral_list">
          <!-- <div class="integ_banner">
              <img src="./dyjf_banner.png" alt="">
          </div> -->
          <div class="tab">
            <tab :line-width=2 active-color='rgb(214,60,50)' v-model="index">
                <tab-item class="vux-center" :selected="selected === item" v-for="(item, index) in list" @on-item-click="handler(item)" :key="index">{{item}}</tab-item>
            </tab>
          </div>
          <router-view></router-view>
        </div>
    </div>
</template>

<script>
import { XHeader, Sticky, Tab, TabItem } from "vux";
import { mapState, mapGetters } from "vuex";

const list = () => ["季度", "年度"];
export default {
  components: {
    XHeader,
    Sticky,
    Tab,
    TabItem
  },
  computed: {
    ...mapGetters(["integPopup"])
  },
  data() {
    return {
      list: list(),
      index: 0,
      selected: "",
      disabled:
        typeof navigator !== "undefined" &&
        /iphone/i.test(navigator.userAgent) &&
        /ucbrowser/i.test(navigator.userAgent)
    };
  },
  watch: {
    $route(to, from) {
      if (to.query.status == "quarter") {
        this.selected = "季度";
      }
    }
  },
  created() {
    let currentSelected = this.$route.query.status;
    if (currentSelected === "quarter") {
      this.selected = "季度";
    } else if (currentSelected === "year") {
      this.selected = "年度";
    }
  },
  methods: {
    handler(item) {
      this.selected = item;
      let path = this.$route.path;
      if (item === "季度") {
        this.$router.replace(`${path}?status=quarter`);
      } else if (item === "年度") {
        this.$router.replace(`${path}?status=year`);
      }
    },
    changChoose() {
      this.$store.dispatch("updateIntegPopup", {
        integPopup: true
      });
    }
  }
};
</script>

<style lang="less">
.integral_status {
  font-size: 0;
  height: 100%;
  background: rgb(245, 245, 249);
  .choose {
    width: 1.375rem;
    height: 1.375rem;
    background: url("./shaixuan.png") no-repeat;
    background-size: 1.375rem 1.375rem;
  }
  .integral_list {
    padding: 2.875rem 0 0;
    height: 100%;
  }
  .integ_banner {
    width: 100%;
    height: 6.75rem;
    overflow: hidden;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .tab {
    position: fixed;
    z-index: 10;
    width: 100%;
  }
  .vux-tab {
    .vux-tab-item {
      font-size: 1.1875rem;
      color: rgb(0, 0, 0);
    }
  }
}
</style>